//根据类型(速度),图标类型,状态 获取图片
function getIconPic(icon_type,status){//,hangxiang

	var icon = new GIcon();
	icon.image = "images/comm/"+status+"_"+icon_type+".png";
	//icon.iconSize = new GSize(24, 24);
	icon.iconAnchor = new GPoint(12, 24);
	icon.infoWindowAnchor = new GPoint(10, 1);
	return icon;
}
var speedForStill = [4,10];
function getIcon(type) {
	//	alert(type);
	var icon = new GIcon();
	if (type == "gray")
		icon.image = "images/comm/gray_01.png";
	else if (type == "red")
		icon.image = "images/comm/red_01.png";
	else if (type == "green")
		icon.image = "images/comm/green_01.png";
	else if (type == "yellow")
		icon.image = "images/comm/yellow_01.png";
	else if (type == "white")
		icon.image = "images/comm/white_01.png";
	////////////////////////////////////////////
	else
		return null;
	//icon.iconSize = new GSize(12, 20);
	//icon.shadowSize = new GSize(20, 20);
	icon.iconSize = new GSize(24, 24);
	icon.iconAnchor = new GPoint(12, 24);
	icon.infoWindowAnchor = new GPoint(10, 1);
	return icon;
}

function getHangXiang(dusu, sudu) {
	if(getHangXiang.arguments.length == 2){
		if(sudu < 10)
			return "......";
	}
	var z = 5;
	var fz = 10;
	var p = 30;
	//              5,355  ;10,350;10-80  ;85-95;   80-100                                                ;280-350
	//	var hangxiang=["正北向","北向","东北向","正东向","东向","东南向","正南向","南向","西南向","正西向","西向","西北向"];
	//	var qujian1 = [z,       fz,    fz,     90-z,    90-fz, 90+fz,  180-z,   180-fz,180+fz, 270-z,   270-fz, 270+fz];
	//	var qujian2 = [360-z,   360-fz,90-fz,  90+z,    90+fz, 180-fz, 180+z,   180+fz,270-fz, 270+z,    270+fz,360-fz];

	var hangxiang = [ "正北向", "北向", "东北向偏北", "东北向", "东北向偏东", "正东向", "东向",
			"东南向偏东", "东南向", "东南向偏南", "正南向", "南向", "西南向偏南", "西南向", "西南向偏西",
			"正西向", "西向", "西北向偏西", "西北向", "西北向偏北" ];
	var qujian1 = [ z, fz, fz, p, 90 - p, 90 - z, 90 - fz, 90 + fz, 90 + p,
			180 - p, 180 - z, 180 - fz, 180 + fz, 180 + p, 270 - p, 270 - z,
			270 - fz, 270 + fz, 270 + p, 360 - p ];
	var qujian2 = [ 360 - z, 360 - fz, p, 90 - p, 90 - fz, 90 + z, 90 + fz,
			90 + p, 180 - p, 180 - fz, 180 + z, 180 + fz, 180 + p, 270 - p,
			270 - fz, 270 + z, 270 + fz, 270 + p, 360 - p, 360 - fz ];

	for ( var i = 0; i < qujian1.length; i++) {
		if (i == 0 || i == 1) {
			if (qujian2[i] <= dusu || dusu <= qujian1[i])
				return hangxiang[i];
		} else {
			if (qujian1[i] <= dusu && dusu <= qujian2[i])
				return hangxiang[i];
		}
	}
	return dusu;
}

function exchange_time(msecond) {
	/*
	if(msecond > 1800)
		return ">30分钟";
	else
		return ".......";
	*/
	var dd;
	var hh;
	var mm;
	var ss;
	//var strTip = "";
	datesub = msecond;
	dd = Math.round(datesub / 86400 + 0.5) - 1;
	hh = Math.round((datesub - dd * 86400) / 3600 + 0.5) - 1;
	mm = Math.round((datesub - dd * 86400 - hh * 3600) / 60 + 0.5) - 1;
	ss = Math.round(datesub - dd * 86400 - hh * 3600 - mm * 60);
	var strtip = "";
	if (dd > 0)
		strtip = strtip + dd + "天";
	if (hh > 0)
		strtip = strtip + hh + "小时";
	if (mm > 0){
		strtip = strtip + mm + "分";
		if(dd > 0)
			return strtip;
	}
	if (ss > 0)
		strtip = strtip + ss + "秒";
	return strtip;
}

function MM_controlSound(sndAction, sndObj) {
	if (eval(sndObj) != null) {
		if (navigator.appName == 'Netscape') {
			eval(sndObj + ((sndAction == 'stop') ? '.stop()' : '.play(false)'));
		} else if (eval(sndObj + ".FileName")) {
			eval(sndObj + ((sndAction == 'stop') ? '.stop()' : '.play()'));
		}
	}
}

//根据目标最新GPS时间(心跳时间)和服务器时间之差、和目标速度，得到目标状态
function getState(heart_time, sudu, stopover_time,iconType) {
	var _stillSpeed = speedForStill[0];
	if(iconType.charAt(0)=="2"&&iconType!="23"){//如果图片类型以2开头，并且部位23s摩托车) 速度才为另一个值
		_stillSpeed = speedForStill[1];
	}
	if (heart_time > 1500)//如果重新搜网也没有收到心跳(25分钟)
		return "white";

//	if (10 < heart_time && heart_time <= 650)
//		return "gray";
	//alert(iconType+","+sudu)

	if (35 < stopover_time)//如果服务器时间减去最新移动定位时间，大于2个信号周期，判读为静止
	return "gray";
	
	if (sudu < _stillSpeed)//
		return "gray";

	if (sudu < 80)
		return "green";

	if (120 > sudu && sudu >= 80)
		return "yellow";

	return "red";
}


function getStateInText(state, sudu) {
	if (state == "white")
		return "离线";

	if (state == "gray")
		return "静止";

	if (sudu < 80)
		return "正常行驶中";

	if (120 > sudu && sudu >= 80)
		return "快速行驶中";

	return "超速行驶中";
}

//得到目标时间 和 服务器时间之差
function getTimeDiff(serverTime, objTime){
	//alert(serverTime + "----" + objTime);
	var timeDiff =  (new Date(serverTime.replace(/-/g, "/")).getTime() - new Date(
			(objTime.split("."))[0].replace(/-/g, "/")).getTime()) / 1000;
	if(timeDiff < 0)//如果目标GPS时间大于服务器时间，设置服务器时间比GPS时间大1秒。
		timeDiff = 1;
	//alert(timeDiff);
	return timeDiff;
}



//转换雅加达时间为北京时间
function getBJTime(oldTime){
	var d = new Date((oldTime.split("."))[0].replace(/-/g, "/"));
	d.setHours(d.getHours()+1);
	//2009/10/24 17:36:14
	//alert(d);
	var month = (d.getMonth() + 1);
	//alert(d.getDay());
	return d.getFullYear() + "-" + month + "-" + d.getDate() +" " 
	+ d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();	
}

function getTimeDiff2(serverTime, objTime){
	
	var timeDiff =  (new Date((serverTime.split("."))[0].replace(/-/g, "/")).getTime() - new Date(
			(objTime.split("."))[0].replace(/-/g, "/")).getTime()) / 1000;
	if(timeDiff < 0)//如果目标GPS时间大于服务器时间，设置服务器时间比GPS时间大1秒。
		timeDiff = 1;
	
	return timeDiff;
}

//根据经度或维度之差，得到地图的缩放比例
function getRoom(diff){
	   //alert("diff="+diff);
		var room =    new Array(0,  1,  2, 3, 4, 5, 6,7,8,  9,   10,  11,  12,  13, 14);
		//var diffArr = new Array(360,180,90,45,23,11,6,3,1.5,0.75,0.37,0.18,0.09,0.04,0);
		var diffArr = new Array(360,180,90,45,22,11,5,2.5,1.25,0.6,0.3,0.15,0.07,0.03,0);
		for(var i = 0; i < diffArr.length; i ++){
//			alert(diffArr[i]);
			if((diff - diffArr[i]) >= 0)
				return room[i];
		}	
		return 14;
	}

//根据一系列经纬度点，得到中间点的坐标
function getCenterPoint(eArr){
	//var min = 0, max = 500;
//	alert(eArr);
	var minJ = 500, minW = 500, maxW = 0, maxJ = 0;
	for(var i = 0; i < eArr.length; i ++){
		//alert			
		ess = eArr[i].split(",");
		if( i == 0){
			maxJ = minJ = ess[1];
			maxW = minW = ess[2];
			continue;
		}
		if(ess[1] > maxJ)
			maxJ = ess[1];			
		if(ess[1] < minJ)
			minJ = ess[1];
		if(ess[2] > maxW)
			maxW = ess[2];
		if(ess[2] < minW)
			minW = ess[2];	
	}
//	alert(minJ);
//	alert(maxJ);

	var diff = maxJ - minJ;
	if(diff < (maxW - minW))
		diff = maxW - minW;
	diff = parseInt(10000 * diff)/10000;
	
	var centerJ = minJ * 1000000 + 1000000 * (maxJ - minJ)/2;
	var centerW = minW * 1000000 + 1000000 * (maxW - minW)/2;
	arr =  new Array();
	arr[0] = centerJ/1000000;
	arr[1] = centerW/1000000;
	arr[2] = diff;
//	alert(arr);
	return arr;
}      
formatDistance_ = function(len2) {
 	  len2 = Math.round(len2);
  	  if (len2 <= 1000) {
  	    return len2 + ' ' + '米';
  	  } else if (len2 <= 1000000) {
  	    return len2 / 1000 + ' ' + '公里';
  	  }
  	  return Math.round(len2 / 1000) + ' ' + '公里';
  	}

formatDistance_2 = function(len2) {
	len2 = Math.round(len2);
	if (len2 <= 1000) {
		return len2 + ' ' + 'M';
	} else if (len2 <= 1000000) {
		return len2 / 1000 + ' ' + 'Km';
	}
	return Math.round(len2 / 1000) + ' ' + 'Km';
}

function drawLine(x0, y0, x, y, sudu){
	if (Math.sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0))>0.0002){ 
        if(sudu > 120) 
           //120以上画深红线
           return new GPolyline([new GLatLng(x0, y0), new GLatLng(x, y),], "#FF0000", 5);
        
        if (sudu > 80)
               //80-120画浅红线
            return new GPolyline([new GLatLng(x0, y0), new GLatLng(x, y),], "#FF00FF", 5);
        
               //80以下--画绿线
        return new GPolyline([new GLatLng(x0, y0), new GLatLng(x, y),], "#00FF00", 5);        
	}
	return null;
}
function getFormatDateTime(dateTime){
	//输入为:2009-05-14 22:35:08 或 2009-05-14 22:35:08.0 格式
	var dotIndex = dateTime.indexOf(".");
	if(dotIndex != -1)
		return dateTime.substring(0, dotIndex);
	return dateTime;
}